/*
Date:20210501 23:24PM
key:再一次狠狠熟悉了unordered_map,当一个结构体有多个变量，往往以pair<结构主键，结构整体>为ky结构放入，即可完美。
// Definition for Employee.
class Employee {
public:
    int id;
    int importance;
    vector<int> subordinates;
};
*/

class Solution {
public:

    int back(unordered_map<int,Employee*>const &S,Employee* const &e,int&re)
    {
        re+=e->importance;
        for(int id:e->subordinates)
        {
            back(S,S.find(id)->second,re);
        }
        return re;
    }

    int getImportance(vector<Employee*> employees, int id) 
    {
        
        unordered_map<int,Employee*> S;
        for(Employee* e:employees)
        {
            S.insert(pair<int,Employee*>(e->id,e));
        }
        int re=0;
        return back(S,S.find(id)->second,re);
    }
};